﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using DotNetNuke;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Services.Search;
using System.Data;

namespace DNNToolkit.Modules.FAQ.Components
{
    /// <summary>
    /// The Controller class for the FAQ.
    /// </summary>
    public class FAQController
    {

        #region Constructors

        public FAQController()
        {
        }

        #endregion

        private readonly DataManager _mgr = new DataManager();

        #region Public Methods


        public const string HeaderTemplate = "<div class='bgimage' style='background-image: url(../DesktopModules/DNNToolkit/FAQ/images/faq.jpg);'><h1 class='hdrtext2'>FAQ</h1></div>";
        public const string FooterTemplate = "";

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// adds an object to the database.
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="objFAQ">The FAQInfo object.</param>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------
        public void CreateFAQ(FAQInfo objFAQ)
        {
            objFAQ.DateTimeStamp = DateTime.Now;
            _mgr.CreateFAQ(objFAQ);
        }


        /// <summary>
        /// Deletes the FAQ.
        /// </summary>
        /// <param name="objFAQ">The obj FAQ.</param>
        public void DeleteFAQ(FAQInfo objFAQ)
        {
            _mgr.DeleteFAQ(objFAQ);
        }


        /// <summary>
        /// Updates the FAQ.
        /// </summary>
        /// <param name="objFAQ">The obj FAQ.</param>
        public void UpdateFAQ(FAQInfo objFAQ)
        {
            _mgr.UpdateFAQ(objFAQ);
        }


        /// <summary>
        /// Gets the FAQ.
        /// </summary>
        /// <param name="FAQID">The FAQ ID.</param>
        /// <param name="moduleID">The module ID.</param>
        /// <returns></returns>
        public FAQInfo GetFAQ(long FAQID, int moduleID)
        {
            return _mgr.GetFAQ(FAQID, moduleID);
        }

        /// <summary>
        /// Searches the FAQ.
        /// </summary>
        /// <param name="filter">The filter.</param>
        /// <param name="moduleID">The module ID.</param>
        /// <returns></returns>
        public List<FAQInfo> SearchFAQ(string filter, int moduleID)
        {
            return _mgr.SearchFAQ(filter, moduleID);
        }

        /// <summary>
        /// Searches the FAQ by filter.
        /// </summary>
        /// <param name="filter">The filter.</param>
        /// <param name="category">The category.</param>
        /// <param name="moduleID">The module ID.</param>
        /// <returns></returns>
        public List<FAQInfo> SearchFAQByFilter(string filter, long categoryID, int moduleID)
        {
            return _mgr.SearchFAQByFilter(filter, categoryID, moduleID);
        }

        /// <summary>
        /// Searches the FAQ by catetory.
        /// </summary>
        /// <param name="category">The category.</param>
        /// <param name="moduleID">The module ID.</param>
        /// <returns></returns>
        public List<FAQInfo> SearchFAQByCatetory(long categoryID, int moduleID)
        {
            return _mgr.SearchFAQByCatetory(categoryID, moduleID);
        }


        /// <summary>
        /// Gets all FAQ category definitions.
        /// </summary>
        /// <returns></returns>
        public List<FAQCategoryDefinitionInfo> GetAllFAQCategoryDefinitions()
        {

            return _mgr.GetAllFAQCategoryDefinitions();
        }

        /// <summary>
        /// Gets the FAQ category definition.
        /// </summary>
        /// <param name="CategoryDefinitionID">The category definition ID.</param>
        /// <returns></returns>
        public FAQCategoryDefinitionInfo GetFAQCategoryDefinition(long CategoryDefinitionID)
        {
            return GetAllFAQCategoryDefinitions().Find(x => x.CategoryDefinitionID == CategoryDefinitionID);
        }

        /// <summary>
        /// Creates the FAQ category definition.
        /// </summary>
        /// <param name="objFAQCategoryDefinition">The obj FAQ category definition.</param>
        public void CreateFAQCategoryDefinition(FAQCategoryDefinitionInfo objFAQCategoryDefinition)
        {
            _mgr.CreateFAQCategoryDefinition(objFAQCategoryDefinition);
        }


        /// <summary>
        /// Updates the FAQ category definition.
        /// </summary>
        /// <param name="objFAQCategoryDefinition">The obj FAQ category definition.</param>
        public void UpdateFAQCategoryDefinition(FAQCategoryDefinitionInfo objFAQCategoryDefinition)
        {
            _mgr.UpdateFAQCategoryDefinition(objFAQCategoryDefinition);
        }


        /// <summary>
        /// Deletes the FAQ category definition.
        /// </summary>
        /// <param name="objFAQCategoryDefinition">The obj FAQ category definition.</param>
        public void DeleteFAQCategoryDefinition(FAQCategoryDefinitionInfo objFAQCategoryDefinition)
        {
            _mgr.DeleteFAQCategoryDefinition(objFAQCategoryDefinition);
        }


        #endregion

    }
}
